package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.domain.SysGoods;
import com.ruoyi.system.service.ISysGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGoodsclassification;
import com.ruoyi.system.service.ISysGoodsclassificationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 供货分类实体Controller
 * 
 * @author ruoyi
 * @date 2020-12-13
 */
@Controller
@RequestMapping("/system/goodsclassification")
public class SysGoodsclassificationController extends BaseController
{
    private String prefix = "system/goodsclassification";

    @Autowired
    private ISysGoodsclassificationService sysGoodsclassificationService;
    @Autowired
    private ISysGoodsService sysGoodsService;
    @RequiresPermissions("system:goodsclassification:view")
    @GetMapping()
    public String goodsclassification()
    {
        return prefix + "/goodsclassification";
    }

    /**
     * 查询供货分类实体列表
     */
    @RequiresPermissions("system:goodsclassification:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysGoodsclassification sysGoodsclassification)
    {
        startPage();
        List<SysGoodsclassification> list = sysGoodsclassificationService.selectSysGoodsclassificationList(sysGoodsclassification);
        return getDataTable(list);
    }

    /**
     * 导出供货分类实体列表
     */
    @RequiresPermissions("system:goodsclassification:export")
    @Log(title = "供货分类实体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysGoodsclassification sysGoodsclassification)
    {
        List<SysGoodsclassification> list = sysGoodsclassificationService.selectSysGoodsclassificationList(sysGoodsclassification);
        ExcelUtil<SysGoodsclassification> util = new ExcelUtil<SysGoodsclassification>(SysGoodsclassification.class);
        return util.exportExcel(list, "goodsclassification");
    }

    /**
     * 新增供货分类实体
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供货分类实体
     */
    @RequiresPermissions("system:goodsclassification:add")
    @Log(title = "供货分类实体", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysGoodsclassification sysGoodsclassification)
    {
        return toAjax(sysGoodsclassificationService.insertSysGoodsclassification(sysGoodsclassification));
    }

    /**
     * 修改供货分类实体
     */
    @GetMapping("/edit/{goodsClassificationId}")
    public String edit(@PathVariable("goodsClassificationId") Long goodsClassificationId, ModelMap mmap)
    {
        SysGoodsclassification sysGoodsclassification = sysGoodsclassificationService.selectSysGoodsclassificationById(goodsClassificationId);
        mmap.put("sysGoodsclassification", sysGoodsclassification);
        return prefix + "/edit";
    }

    /**
     * 修改保存供货分类实体
     */
    @RequiresPermissions("system:goodsclassification:edit")
    @Log(title = "供货分类实体", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysGoodsclassification sysGoodsclassification)
    {
        return toAjax(sysGoodsclassificationService.updateSysGoodsclassification(sysGoodsclassification));
    }

    /**
     * 删除供货分类实体
     */
    @RequiresPermissions("system:goodsclassification:remove")
    @Log(title = "供货分类实体", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysGoodsclassificationService.deleteSysGoodsclassificationByIds(ids));
    }
    /**
     * 货物名称列表
     */
    @RequiresPermissions("system:goodsclassification:list")
    @GetMapping("/detail/{goodsClassificationId}")
    public String detail(@PathVariable("goodsClassificationId") Long goodsClassificationId, ModelMap mmap, HttpSession httpSession)
    {
        mmap.put("mingcheng", sysGoodsclassificationService.selectSysGoodsclassificationById(goodsClassificationId));
        mmap.put("classifications", sysGoodsclassificationService.selectSysGoodsclassificationList(null));
        httpSession.setAttribute("fenleiId",goodsClassificationId);
        /*SysGoods sysGoods = new SysGoods();
        sysGoods.setGoodsClassificationId(goodsClassificationId);
        mmap.put("sysGoods",sysGoods);
        *//*return "system/goods/goods";*//*
        HttpUtils httpUtils = new HttpUtils();
        httpUtils.sendPost("/system/goods/list",goodsClassificationId+"");*/
        return "system/goods/goods";
    }
    /**
     * 货物名称列表
     */
    @RequiresPermissions("system:goodsclassification:list")
    @GetMapping("/listdetail/{id}")
    public String listdetail(@PathVariable("id")Long id,ModelMap mmap)
    {
        List<SysGoodsclassification> list = sysGoodsclassificationService.selectSysGoodList();
        mmap.put("googsTypes",list);
        mmap.put("id",id);
        return prefix + "/grant";
    }


}
